package com.lyz.dataStructure.algorithm.jingdong2020;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 20:59
 * @Description:
 **/

import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/8/24 20:59
 *@Description:
 **/
public class Main3 {
    static int[][] test;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] output = new int[2 * n + 1];
        int length = 2 * n + 1;
        test = new int[length][length];
        for (int i = 0; i < m; i++) {
            int ls = in.nextInt();
            int lm = in.nextInt();
            test[ls][lm] = 1;
        }
        in.close();
        while (check(length)) {
            for (int i = 0; i < length; i++) {
                int temp = 0;
                for (int j = 0; j < length; j++) {
                    if (test[i][j] == 1) {
                        temp++;
                    }
                }
                if (temp > 0) {
                    output[i] = 1;
                    clear(i, length);
                }
            }
        }
        int result = 0;
        for (int j = 0; j < length; j++) {
            if (output[j] == 1) {
                result++;
            }

        }
        System.out.println(result);
        for (int j = 0; j < length; j++) {
            if (output[j] == 1) {
                System.out.println(j);
            }

        }
    }
    private static boolean check(int length) {
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < length; j++) {
                if (test[i][j] == 1) {
                    return true;
                }
            }
        }
        return false;
    }

    private static void clear(int x, int length) {
        for (int i = 0; i < length; i++) {
            test[x][i] = 0;
        }
        for (int j = 0; j < length; j++) {
            test[j][x] = 0;
        }
    }
}
